package com.fire.service.impl;

import com.fire.dao.ITeacherDao;
import com.fire.dao.impl.TeacherDaoImpl;
import com.fire.domain.Teacher;
import com.fire.factory.Factory;
import com.fire.service.ITeacherService;

import java.io.IOException;
import java.time.LocalDateTime;
import java.util.ArrayList;

public class TeacherServiceImpl implements ITeacherService {
    ITeacherDao teaDao= Factory.getTeacherDaoImpl();
    @Override
    public LocalDateTime isHaveChance(String name, LocalDateTime now) throws IOException {
        LocalDateTime beforeTime=teaDao.isHaveChance(name,now);
        /*Duration duration = Duration.between(now, beforeTime);
        long minutes = duration.toMinutes();*/
        /*System.out.println("上一个时间"+beforeTime);
        System.out.println("传入时间"+now);
        System.out.println("相差时间"+minutes);*/
        return beforeTime;
    }

    @Override
    public int Login(String name, String password) throws IOException {
        return teaDao.Login(name,password);
    }

    @Override
    public boolean isExist(String id) throws IOException {
        ArrayList<Teacher> list;
        list=teaDao.findAll();
        for (Teacher teacher : list) {
            if(teacher.getId().equals(id)){
                return true;
            }
        }
        return false;
    }

    @Override
    public void Regirter(String id, String p1) throws IOException {
        teaDao.Register(id,p1);
    }

    @Override
    public LocalDateTime WriterAndClear(String name, LocalDateTime now) throws IOException {
        LocalDateTime time=teaDao.WriterAndClear(name,now);
        return time;
    }

    @Override
    public LocalDateTime CloseTime(String name) throws IOException {
        LocalDateTime time=teaDao.CloseTime(name);
        return time;
    }

    @Override
    public LocalDateTime RegisterTime(String name) throws IOException {
        LocalDateTime time=teaDao.RegisterTime(name);
        return time;
    }

    @Override
    public void WriteCloseTime(String name) throws IOException {
        teaDao. WriteCloseTime( name);
    }
}
